#!/usr/bin/python
from random import randint
import os 

emes= [1, 1.5, 2, 3]
emes= map(lambda x:int(x*625), emes) 
print "emes: " + str(emes)

sigmas= [0, 1, 2, 3, 4]
sigmas= map(lambda x:"0." + "0"*x + "1", sigmas)
print "sigmas: " + str(sigmas)

test_case_pattern= lambda x:x.lower()[len(x)-4:]==".png"
test_cases= filter(test_case_pattern,os.listdir('../../test'))
print "test_cases: " + str(test_cases)

seeds= [randint(0, 65535) for i in range(0, len(test_cases))]
seeds[0]= 46505 
seeds[1]= 12396
seeds[2]= 42724
print "seeds: " + str(seeds)
print "*+" * 20

if not os.path.exists("results"):
	os.mkdir("results")



def main():
	numero_caso= 1
	for test_case,seed in zip(test_cases,seeds):
		for m in emes:
			for s in sigmas:
				print "caso %d de %d" % (numero_caso, len(emes)*len(sigmas)*len(test_cases))
				print "\timagen: " + test_case
				print "\tsigma: " + str(s)
				print "\tseed: " + str(seed)
				print "\tm: " + str(m)

				test_case_prefix= test_case[:len(test_case) - 4]

				folder_name=test_case_prefix + "_"  
				folder_name+=str(seed) + "_" 
				folder_name+=str(m) + "_" 
				folder_name+=s

				if os.path.exists("results/" + folder_name + "/terminado"):
					numero_caso+=1
					continue
				elif os.path.exists("results/" + folder_name):
					os.rmdir("results/" + folder_name)

				os.mkdir("results/" + folder_name)

				exec_str="./proc.sh "  
				exec_str+="../../test/" + test_case + " "  
				exec_str+=str(seed) + " " 
				exec_str+=str(m) + " " 
				exec_str+=s + " " 
				exec_str+=test_case_prefix 
				
#			print exec_str
				if os.system(exec_str) != 0:
					return	

				output_proc_files= "input_gen_rayos.txt output_gen_rayos.txt output_rayitos.txt "
				output_proc_files+= "error_" + test_case_prefix + ".txt " + test_case_prefix+".png "
				output_proc_files+=test_case_prefix+".txt "

#			print "mv " + output_proc_files + "results/"+folder_name
				os.system("mv " + output_proc_files + "results/"+folder_name)
				
				os.system("echo listo > results/"+folder_name+"/terminado")

				numero_caso+=1


		


main()

